# coding:utf-8

from docx import Document
from docx.shared import RGBColor
from docx.oxml.ns import qn
document = Document()
document.styles['Normal'].font.name = u'微软雅黑'
document.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')

def write_zhangjie(zhangjie):
    document.add_heading(zhangjie, 0)

def write_question(leixing,questions):
    document.add_heading(leixing, level=2)
    document.add_paragraph('love', style='Intense Quote')
    for question in questions:
        runD = ''
        # title
        p = document.add_paragraph(question.title, style='List Number')
        # answer
        run = p.add_run(question.answer)
        run.font.color.rgb = RGBColor(255, 0, 0)
        #print(question.A)
        if question.A:
            runA = p.add_run('\n\t' + 'A.' + str(question.A))
        if question.B:
            runB = p.add_run('\n\t' + 'B.' + str(question.B))
        if question.C:
            runC = p.add_run('\n\t' + 'C.' + str(question.C))
        if question.D:
            runD = p.add_run('\n\t' + 'D.' + str(question.D))

        if 'A' in question.answer:
            runA.font.color.rgb = RGBColor(22, 120, 190)
        if 'B' in question.answer:
            runB.font.color.rgb = RGBColor(22, 120, 190)
        if 'C' in question.answer:
            runC.font.color.rgb = RGBColor(22, 120, 190)
        if runD:
            if 'D' in question.answer:
                runD.font.color.rgb = RGBColor(22, 120, 190)
        # jiexi
        if question.jiexi:
            runj = p.add_run('\n\t' + question.jiexi)
            runj.bold = True
            runj.font.color.rgb = RGBColor(139,0,0)
    document.save('8-14章new.docx')
def write(zhangjie,leixing,questions):
    write_zhangjie(zhangjie)
    write_question(leixing, questions)
